Skip to main content

All Questions

3votes
2answers
184views

Find the join of two set partitions

Two partitions of a set have a greatest lower bound (meet) and a least upper bound (join). See here: Meets and joins in the lattice of partitions (Math SE) The meet is easy to calculate. I am trying ...
Watchduck's user avatar
3votes
1answer
82views

Number of partitions of (a,b) into k distinct parts which sum up to (a,b)

Problem set This is somewhat a generalization of the famous partition of integer n into k parts. Given two integers ...
linuxbeginner's user avatar
7votes
2answers
1kviews

Find all combinations of length 3 whose sum is divisible by a given number

I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...
NFeruch - FreePalestine's user avatar
1vote
1answer
90views

An algorithm that minimizes the number of ingredients necessary

I am working on a code that will minimize the number of ingredients necessary to make some dishes. Each dish can be prepared in an arbitrary large number of ways, with combinations of two ingredients. ...
adrienlucca.net's user avatar
1vote
1answer
130views

Subset Product Algorithm

Subset Product is an NP-complete problem and is my favorite problem. So, I've written a slightly smarter way of solving the problem. Will performance impact matter if I use multi-cpus and my GPU? Do ...
The T's user avatar
5votes
2answers
2kviews

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
Atvin's user avatar
1vote
2answers
134views

Get the next bigger number by rearranging the digits of the input integer

...
Edmerson Pizarra's user avatar
2votes
1answer
91views

Count the different positions reached in a cycle of permutations

I have come across a problem on cyclic permutations. It is about swapping numbers around. It starts out with input N < 100,000 which makes the first N natural numbers as orders: 1 2 3 ... N-1 N ...
halcyon44's user avatar
4votes
1answer
93views

Filter out unwanted substrings while generating all possible relevant substrings

Write a Program that determines where to add periods to a decimal string so that the resulting string is a valid IP address. There may be more than one valid IP address corresponding to a string, ...
Brayoni's user avatar
8votes
3answers
294views

Refactor the code which performs "cross-product", "reduce", "product of list" and "sum of list"

I have come up with a sequence of steps to find the maximum product of y positive numbers which add up to x. But the program is ...
Yozachar's user avatar
7votes
2answers
6kviews

Permutations with replacement in Python

Many a times, I've had the need to use a permutations with replacement function. So, I've written a function to do just that: ...
Sriv's user avatar
  • 2,790
7votes
2answers
3kviews

Sums of all sublists

The parts_sums function in the code takes a list as parameter and then returns sum of all sub-lists present in the list. e.g. if, ...
Akhil Pandey's user avatar
5votes
1answer
2kviews

Project Euler 76: Counting summations

Project Euler Problem 76 asks: How many different ways can one hundred be written as a sum of at least two positive integers? My code is correct but just works slowly. ...
camarman's user avatar
1vote
1answer
90views

Algorithmic complexity of this algorithm to find all ordered permutations of length X

I have written a recursive function to generate the list of all ordered permutations of length X for a list of chars. For instance: ['a', 'b', 'c', 'd'] with X=2 will give [['a', 'a'], ['a', 'b'], ['...
user avatar
4votes
2answers
2kviews

Steinhaus-Johnson-Trotter Algorithm

I began to program a little while ago and tried to implement my first algorithm: the Steinhaus-Johnson-Trotter algorithm. This algorithm generates a sequence of permutations of \$n\$ elements such ...
Onur C.Y.'s user avatar

153050per page
close